﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;

namespace gChartSharp
{
    /// <summary>
    /// http://code.google.com/apis/chart/#hor_line_marker
    /// </summary>
    public class ChartRangeMarker : IChartParam
    {

        /// <summary>
        /// The name of the API
        /// </summary>
        public string Name { get { return "chm"; } }


        /// <summary>
        /// The type of marker
        /// </summary>
        public RangeMarkerType RangeMarkerType { get; set; }


        /// <summary>
        /// The color of the marker
        /// </summary>
        public Color Color { get; set; }


        /// <summary>
        /// Starting point - value must be between 0.00 and 1.00
        /// </summary>
        public decimal StartPoint 
        {
            get { return mStartPoint; }
            set 
            {
                if (value > 0M && value < 1M)
                    mStartPoint = Math.Round(value, 2);
                else
                    throw new Exception("StartPoint must be between 0.00 and 1.00");
            } 
        }
        private decimal mStartPoint;


        /// <summary>
        /// Ending point - value must be between 0.00 and 1.00
        /// </summary>
        public decimal EndPoint
        {
            get { return mEndPoint; }
            set
            {
                if (value > 0M && value < 1M)
                    mEndPoint = Math.Round(value, 2);
                else
                    throw new Exception("EndPoint must be between 0.00 and 1.00");
            }
        }
        private decimal mEndPoint;


        /// <summary>
        /// Constructor to initialize all properties
        /// </summary>
        /// <param name="rangeMarkerType"></param>
        /// <param name="color"></param>
        /// <param name="startPoint"></param>
        /// <param name="endPoint"></param>
        public ChartRangeMarker(RangeMarkerType rangeMarkerType, Color color, decimal startPoint, decimal endPoint)
        {
            this.RangeMarkerType = rangeMarkerType;
            this.Color = color;
            this.StartPoint = startPoint;
            this.EndPoint = endPoint;
        }


        // Hide the default constructor
        private ChartRangeMarker() { }


        /// <summary>
        /// Render the text of the API
        /// </summary>
        /// <returns></returns>
        public string Render()
        {
            StringBuilder sb = new StringBuilder();
            sb.Append(this.RangeMarkerType.ToString());
            sb.Append(",");
            sb.Append(ChartHelper.ConvertColorToHex(Color));
            sb.Append(",0,"); // <any value> is ignored. 
            sb.Append(this.StartPoint);
            sb.Append(",");
            sb.Append(this.EndPoint);
            return sb.ToString();
        }
    }


    public enum RangeMarkerType
    {
        /// <summary>
        /// Horizontal
        /// </summary>
        r,

        /// <summary>
        /// Vertical
        /// </summary>
        R
    }
}
